﻿using UnityEngine;
using System;
using System.Collections;

namespace TCG
{
	public class GameAsset<T> 
	{
		public GameAsset (uint id, T asset)
		{
			m_assetId = id;
			m_asset = asset;
			m_refCount = 0;
		}

		public uint id
		{
			get { return m_assetId; }
		}

		public T asset
		{
			get { return m_asset; }
		}

		public uint refCount 
		{
			get { return m_refCount; }
		}

		public void IncRef ()
		{
			m_refCount += 1;
		}

		public void DecRef ()
		{
			m_refCount -= 1;
			if (m_refCount < 0)
			{
				throw new Exception ("引用计数不应该小于0");
			}
		}

		public override string ToString ()
		{
			return string.Format ("[GameAsset: id={0}, asset={1}, refCount={2}]", id, asset, refCount);
		}

		uint m_assetId;

		T m_asset;

		uint m_refCount;
	}
}
